package com.yidu.logisticssystem.service.impl;

import com.yidu.logisticssystem.entity.LogisticsCar;
import com.yidu.logisticssystem.dao.LogisticsCarDao;
import com.yidu.logisticssystem.entity.vo.CarVo;
import com.yidu.logisticssystem.service.LogisticsCarService;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;

/**
 * 车辆信息表(LogisticsCar)表服务实现类
 *
 * @author makejava
 * @since 2021-03-12 14:34:50
 */
@Service("logisticsCarService")
public class LogisticsCarServiceImpl implements LogisticsCarService {
    @Resource
    private LogisticsCarDao logisticsCarDao;

    /**
     * 通过ID查询单条数据
     *
     * @param mapId 主键
     * @return 实例对象
     */
    @Override
    public LogisticsCar queryById(Integer mapId) {
        return this.logisticsCarDao.queryById(mapId);
    }

    /**
     * 查询多条数据
     *
     * @param offset 查询起始位置
     * @param limit  查询条数
     * @return 对象列表
     */
    @Override
    public List<LogisticsCar> queryAllByLimit(int offset, int limit) {
        return this.logisticsCarDao.queryAllByLimit(offset, limit);
    }

    /**
     * 新增数据
     *
     * @param logisticsCar 实例对象
     * @return 实例对象
     */
    @Override
    public LogisticsCar insert(LogisticsCar logisticsCar) {
        this.logisticsCarDao.insert(logisticsCar);
        return logisticsCar;
    }

    /**
     * 修改数据
     *
     * @param logisticsCar 实例对象
     * @return 实例对象
     */
    @Override
    public LogisticsCar update(LogisticsCar logisticsCar) {
        this.logisticsCarDao.update(logisticsCar);
        return this.queryById(logisticsCar.getCarId());
    }

    /**
     * 通过主键删除数据
     *
     * @param carId 主键
     * @return 是否成功
     */
    @Override
    public int deleteById(Integer carId) {
        return this.logisticsCarDao.deleteById(carId);
    }

    /**
     * 查询全部
     * @param carVo
     * @return
     */
    @Override
    public List<CarVo> queryAll(CarVo carVo) {
        return this.logisticsCarDao.queryAll(carVo);
    }

    /**
     * 新增
     * @param logisticsCar
     * @return
     */
    @Override
    public int insertSelective(LogisticsCar logisticsCar) {
        return this.logisticsCarDao.insertSelective(logisticsCar);
    }

    /**
     * 批量删除
     * @param ids
     * @return
     */
    @Override
    public int deleteAll(String ids) {
        //将,分隔的字符串分隔成数组,传入到dao中
        String [] idArray = ids.split(",");
        return logisticsCarDao.deleteAll(idArray);
    }


    /**
     * 根据地区查闲置车辆
     * @param mapId
     * @return
     */
    @Override
    public List<LogisticsCar> queryMapId(String mapId) {
        return this.logisticsCarDao.queryMapId(mapId);
    }

    /**
     * 根据车牌修改状态
     * @param logisticsCar
     * @return
     */
    @Override
    public int updateCarNum(LogisticsCar logisticsCar) {
        return this.logisticsCarDao.updateCarNum(logisticsCar);
    }
}
